home *** CD-ROM | disk | FTP | other *** search
Wrap
//Well, this fights for your right to click - let's go for it ... var rtc = { blinkTimer: 0, delay: 1500, prompts: Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService), LOG: function(text) { var consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService); consoleService.logStringMessage(String(text)); }, getPrefs: function() { var prefstr = navigator.preference("extensions.rtc.prefs"); if(!prefstr || prefstr.length < navigator.preference("extensions.rtc.prefsdefault").length) //possibly updated addon rtc.resetPrefs(); var p = prefstr.split(","); for(i = 0; i < p.length; i++){ try{ p[i] = parseInt(p[i]); }catch(e){alert("RTC, error loading preferences: " + e);} //rtc.resetPrefs(); break; } return p; }, savePrefs: function(p) { var prefstr = p.join(",") navigator.preference("extensions.rtc.prefs", prefstr); }, resetPrefs: function() { navigator.preference("extensions.rtc.prefs", navigator.preference("extensions.rtc.prefsdefault")); }, optionsLoad: function() { var p = rtc.getPrefs(); for(i = 0; i < p.length; i++) { if(el = document.getElementById(String(i))) el.checked = p[i]; } }, optionsSave: function() { var p = rtc.getPrefs(); for(i = 0; i < p.length; i++) { if(el = document.getElementById(String(i))) p[i] = el.checked - 0; } rtc.savePrefs(p); }, captureClick: function(event){ rightClick = false; if(event.which && event.which == 3) rightClick = true; else if (event.button && event.button == 2) rightClick = true; if(!rightClick)//left click { rtc.buttonrun(); return; } //right click... }, openConfigWindow: function() { window.openDialog('chrome://rtc/content/rtcoptions.xul', '_blank', 'chrome=yes,modal=yes,resizable=no,centerscreen=yes'); }, populateSBContext: function() { var mPopup = document.getElementById("rtc-statusbarcontextmenu"); if(!mPopup) return; while (mPopup.hasChildNodes()) { mPopup.removeChild(mPopup.firstChild); } //add items var mi = mPopup.appendChild(document.createElement("menuitem")); mi.setAttribute("oncommand", "rtc.openConfigWindow()"); mi.setAttribute("label", "Options"); }, buttonrun: function(){ var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator); if(wm && wm.getMostRecentWindow("navigator:browser") && wm.getMostRecentWindow("navigator:browser").content) rtc.run(wm.getMostRecentWindow("navigator:browser").content.document, true); }, parse: function(clicked, imgArr, topwin){ //frames and iframes rtc.enable(topwin.document, clicked, imgArr); for (var i=0; i < topwin.frames.length; i++) rtc.parse(clicked, imgArr, topwin.frames[i]); }, run: function(doc, clicked){ navigator.preference("dom.event.contextmenu.enabled", false); navigator.preference("nglayout.events.dispatchLeftClickOnly", true);//not work currently due to Firefox bug if(!doc instanceof HTMLDocument || !doc.location || !doc.getElementsByTagName('head')[0]) return; doc.imgs = []; var topwin = doc.defaultView.top; rtc.parse(clicked, doc.imgs, topwin); //parse frames and execute RTC (enable, collect images, ...) var p = rtc.getPrefs(); if(p[26]) { doc.documentElement.innerHTML = ""; //build empty document var head = doc.createElement('head'); doc.documentElement.appendChild(head); var elem = doc.createElement('title') head.appendChild(elem); elem.textContent = "RightToClick Image View"; doc.documentElement.appendChild(doc.createElement('body')); elem = doc.createElement('div'); doc.body.appendChild(elem); elem.style.setProperty("max-width", (window.innerWidth - 10) + "px", "important"); elem.style.setProperty("max-height", (window.innerHeight - 150) + "px", "important"); elem.style.setProperty("overflow", "auto", "important"); var known = "";; for (i = 0; i < doc.imgs.length; i++) //add collected images { if(known.indexOf(doc.imgs[i]) != -1) //prevent duplicates continue; known += doc.imgs[i]; var newimg = doc.createElement('img'); newimg.src = String(doc.imgs[i]); elem.appendChild(newimg); //also recreate background images as normal images newimg.style.setProperty("max-width", "350px", "important"); newimg.style.setProperty("max-height", "350px", "important"); } doc.defaultView.scrollbars.visible = true; window.scrollbars.visible = true; doc.defaultView.scrollbars.hidden = false; window.scrollbars.hidden = false; } doc.imgs = null; }, isEventListenerMatch: function(p,t){ if( (p[0] && (t=="focus")) || (p[1] && (t=="selectstart" || t=="copy" || t=="paste" || t=="cut")) || (p[4] && (t=="contextmenu")) || (p[2] && (t=="dragstart" || t=="drag" || t=="dragover")) || (p[3] && (t=="mouseup" || t=="mousedown" || t=="click")) || (p[5] && (t=="mouseover" || t=="mouseout" || t=="mousemove")) || (p[6] && (t=="dblclick")) || (p[7] && (t=="keydown" || t=="keyup" || t=="keypress")) ) return true; return false; }, getFuncName: function(stringValue){ var funcNamePattern = /function\s*([^\(]*)/mi; var funcName = funcNamePattern.exec(stringValue); if (funcName && funcName[1]) return funcName[1]; return null; }, enable: function(doc, clicked, imgArr){ var elem, i; var win = doc.defaultView; var p = rtc.getPrefs(); var killEventListeners = " "; var removeIDs = " "; //rtc.LOG("Parsing " + doc.location.href); //part 1: Disarm eventlisteners try{ if(p[24]){ var eventListenerService; //Disable site's non-anonymous eventListeners try{ eventListenerService = Components.classes["@mozilla.org/eventlistenerservice;1"].getService(Components.interfaces.nsIEventListenerService); }catch(e){} if(eventListenerService) //FF version 3.7 minimum needed { var allElements = doc.getElementsByTagName('*'); for (i = 0; i < allElements.length; i++) //all element listeners { var elsi = eventListenerService.getListenerInfoFor(allElements[i]); for (z = 0; z < elsi.length; z++) { if(rtc.isEventListenerMatch(p, elsi[z].type)) { if (funcName = rtc.getFuncName(elsi[z].stringValue)) { if (!allElements[i].id || doc.getElementById(allElements[i].id) != allElements[i]) { allElements[i].id = "rtc-ceid" + Math.random(); var eventobject = "document.getElementById('" + allElements[i].id + "')"; removeIDs += eventobject + ".removeAttribute('id'); "; }else var eventobject = "document.getElementById('" + allElements[i].id + "')"; killEventListeners += eventobject + ".removeEventListener('" + elsi[z].type + "', " + funcName + "," + elsi[z].capturing + "); "; } } } } var elsi = eventListenerService.getListenerInfoFor(doc); //object document listeners for (z = 0; z < elsi.length; z++) { if(rtc.isEventListenerMatch(p, elsi[z].type)) { if (funcName = rtc.getFuncName(elsi[z].stringValue)) killEventListeners += "document.removeEventListener('" + elsi[z].type + "', " + funcName + "," + elsi[z].capturing + "); "; } } var elsi = eventListenerService.getListenerInfoFor(win); //object window listeners for (z = 0; z < elsi.length; z++) { if(rtc.isEventListenerMatch(p, elsi[z].type)) { if (funcName = rtc.getFuncName(elsi[z].stringValue)) killEventListeners += "window.removeEventListener('" + elsi[z].type + "', " + funcName + "," + elsi[z].capturing + "); "; } } killEventListeners += removeIDs; } //Firefox without ELS support doc.body = doc.body.cloneNode(true); //remove all body eventlisteners doc.addEventListener('click', function (event) {var cm = document.getElementById("contentAreaContextMenu"); if(event.button == 2) cm.openPopupAtScreen(event.screenX, event.screenY, false); else if(event.target.href || event.target.src) doc.location = event.target.href ? event.target.href:event.target.src;} , true); } }catch(e){rtc.LOG("RTC exception-1: " + e);} //part 2: Disable site's event attributes (needs to be injected in HTML <head> for this) and remove onEvent-attributes try{ var head_tag = doc.getElementsByTagName('head')[0]; var script_tag = doc.createElement('script'); script_tag.setAttribute('type', 'text/javascript'); script_tag.setAttribute('id', 'buttonscr'); var text ="function rtcenable(){var P=[" + p + "]; try{if(P[0]) document.body.onfocus = null; if(P[1]) document.body.oncopy= null; if(P[1]) document.body.onselectstart = null;if(P[2]) document.body.ondragover = null; if(P[2]) document.body.ondrag = null; if(P[2]) document.body.ondragstart = null;if(P[3]) document.body.onmouseup = null;if(P[3]) document.body.onmousedown = null;if(P[3]) document.body.onclick = null;if(P[4]) document.body.oncontextmenu = null;if(P[5]) document.body.onmouseover = null;if(P[5]) document.body.onmouseout = null;if(P[5]) document.body.onmousemove = null;if(P[6]) document.body.ondblclick = null;if(P[7]) document.body.onkeydown = null;if(P[7]) document.body.onkeyup = null;if(P[7]) document.body.onkeypress = null;if(P[0]) document.onfocus = null;if(P[1]) document.oncopy = null;if(P[1]) document.onselectstart = null;if(P[2]) document.ondragover = null;if(P[2]) document.ondrag = null;if(P[2]) document.ondragstart = null;if(P[3]) document.onmouseup = null; if(P[3]){ document.onmousedown = null;}if(P[3]) document.onclick = null;if(P[4]) document.oncontextmenu = null;if(P[5]) document.onmouseover = null;if(P[5]) document.onmouseout = null;if(P[5]) document.onmousemove = null;if(P[6]) document.ondblclick = null;if(P[7]) document.onkeydown = null;if(P[7]) document.onkeyup = null;if(P[7]) document.onkeypress = null;if(P[0]) window.onfocus = null;if(P[1]) window.oncopy = null;if(P[1]) window.onselectstart = null;if(P[2]) window.ondragover = null;if(P[2]) window.ondrag = null;if(P[2]) window.ondragstart = null;if(P[3]) window.onmouseup = null; if(P[3]){ window.onmousedown = null;}if(P[3]) window.onclick = null;if(P[4]) window.oncontextmenu = null;if(P[5]) window.onmouseover = null;if(P[5]) window.onmouseout = null;if(P[5]) window.onmousemove = null;if(P[6]) window.ondblclick = null;if(P[7]) window.onkeydown = null;if(P[7]) window.onkeyup = null;if(P[7]) window.onkeypress = null;}catch(e){}"; text += " var elements = document.getElementsByTagName('*'); for (i = 0; i < elements.length; i++){var el = elements[i]; "; text += " if(P[0] && el.hasAttribute('onfocus')) try{el.removeAttribute('onFocus');}catch(e){} "; text += " if(P[0]) try{el.onfocus=null;}catch(e){} "; text += " if(P[0]) try{el.style.setProperty('-moz-user-focus', 'normal', 'important');}catch(e){} "; text += " if(P[0]) try{el.style.setProperty('-moz-user-input', 'enabled', 'important');}catch(e){} "; text += " if(P[1] && el.hasAttribute('onselectstart')) try{el.removeAttribute('onselectstart');}catch(e){} "; text += " if(P[1] && el.hasAttribute('oncopy')) try{el.removeAttribute('oncopy');}catch(e){} "; text += " if(P[1] && el.hasAttribute('onpaste')) try{el.removeAttribute('onpaste');}catch(e){} "; text += " if(P[1] && el.hasAttribute('oncut')) try{el.removeAttribute('oncut');}catch(e){} "; text += " if(P[1]) try{el.style.setProperty('-moz-user-select', 'text', 'important');}catch(e){} "; text += " if(P[1]) try{el.style.setProperty('cursor', '', '');}catch(e){} "; text += " if(P[1]) try{el.oncopy=null;}catch(e){} "; text += " if(P[1]) try{el.onpaste=null;}catch(e){} "; text += " if(P[1]) try{el.oncut=null;}catch(e){} "; text += " if(P[1]) try{el.onselectstart=null;}catch(e){} "; text += " if(P[4] && el.hasAttribute('oncontextmenu')) try{el.removeAttribute('oncontextmenu');}catch(e){} "; text += " if(P[4]) try{el.oncontextmenu=null;}catch(e){} "; text += " if(P[2] && el.hasAttribute('ondragover')) try{el.removeAttribute('ondragover');}catch(e){} "; text += " if(P[2] && el.hasAttribute('ondrag')) try{el.removeAttribute('ondrag');}catch(e){} "; text += " if(P[2] && el.hasAttribute('ondragstart')) try{el.removeAttribute('ondragstart');}catch(e){} "; text += " if(P[2]) try{el.ondragover=null;}catch(e){} "; text += " if(P[2]) try{el.ondrag=null;}catch(e){} "; text += " if(P[2]) try{el.ondragstart=null;}catch(e){} "; text += " if(P[3] && el.hasAttribute('onmouseup')) try{el.removeAttribute('onmouseup');}catch(e){} "; text += " if(P[3] && el.hasAttribute('onmousedown')) try{el.removeAttribute('onmousedown');}catch(e){} "; text += " if(P[3] && el.hasAttribute('onclick')) try{el.removeAttribute('onclick');}catch(e){} "; text += " if(P[3]) try{el.onmouseup=null;}catch(e){} "; text += " if(P[3]) try{el.onmousedown=null;}catch(e){} "; text += " if(P[3]) try{el.onclick=null;}catch(e){} "; text += " if(P[5] && el.hasAttribute('onmouseover')) try{el.removeAttribute('onmouseover');}catch(e){} "; text += " if(P[5] && el.hasAttribute('onmouseout')) try{el.removeAttribute('onmouseout');}catch(e){} "; text += " if(P[5] && el.hasAttribute('onmousemove')) try{el.removeAttribute('onmousemove');}catch(e){} "; text += " if(P[5]) try{el.onmouseover=null;}catch(e){} "; text += " if(P[5]) try{el.onmouseout=null;}catch(e){} "; text += " if(P[5]) try{el.onmousemove=null;}catch(e){} "; text += " if(P[6] && el.hasAttribute('ondblclick')) try{el.removeAttribute('ondblclick');}catch(e){} "; text += " if(P[6]) try{el.ondblclick=null;}catch(e){} "; text += " if(P[7] && el.hasAttribute('onkeydown')) try{el.removeAttribute('onkeydown');}catch(e){} "; text += " if(P[7] && el.hasAttribute('onkeyup')) try{el.removeAttribute('onkeyup');}catch(e){} "; text += " if(P[7] && el.hasAttribute('onkeypress')) try{el.removeAttribute('onkeypress');}catch(e){} "; text += " if(P[7]) try{el.onkeydown=null;}catch(e){}"; text += " if(P[7]) try{el.onkeyup=null;}catch(e){}"; text += " if(P[7]) try{el.onkeypress=null;}catch(e){}"; text += " if(P[8] && el.hasAttribute('disabled')) try{el.removeAttribute('disabled');}catch(e){} "; text += " if(P[8] && el.hasAttribute('readonly')) try{el.removeAttribute('readonly');}catch(e){} "; text += " if(P[8]) try{el.style.setProperty('-moz-user-modify', 'read-write', 'important');}catch(e){} "; text += " if(P[8]) try{el.disabled=false;}catch(e){}"; text += " if(P[8]) try{el.readonly=false;}catch(e){}"; text += " }"; //Disarm document and window eventlisteners if(p[24]){ text += " if(!document.docevents) document.docevents = []; for(var i= 0; i < document.docevents.length; i++) document.removeEventListener(document.docevents[i][0], document.docevents[i][1], document.docevents[i][2]); "; text += " if(!document.winevents) document.winevents = []; for(var i= 0; i < document.winevents.length; i++) document.removeEventListener(document.winevents[i][0], document.winevents[i][1], document.winevents[i][2]); "; } text += " var rtcexecuted = document.createElement('div');rtcexecuted.id = 'rtc-executed';document.body.appendChild(rtcexecuted); } document.addEventListener('load', function(){setTimeout(rtcenable," + rtc.delay + ");},true); rtcenable(); "; text += " var buttonscript = document.getElementById('buttonscr'); buttonscript.parentNode.removeChild(buttonscript); "; text += killEventListeners; script_tag.text = text; head_tag.appendChild(script_tag); }catch(e){rtc.LOG("RTC exception-2: " + e);} //part 3: Disarm or disable potentially evil functions try{ if(typeof win.wrappedJSObject != "undefined") { if(p[20]) win.wrappedJSObject.setTimeout = function () { win.wrappedJSObject.setTimeout = function() {}; return null; } if(p[20]) win.wrappedJSObject.setInterval = function () { win.wrappedJSObject.setInterval = function() {}; return null; } if(p[21]) win.wrappedJSObject.showModalDialog = function () { win.wrappedJSObject.showModalDialog = function() {}; return null; } } }catch(e){rtc.LOG("RTC exception-3: " + e);} if(p[25] && !p[26]) rtc.setStylesDisabled(true, doc); //disable CSS styles //extract images if(p[26]) { var allElements = doc.getElementsByTagName('*'); //search background images for (i = 0; i < allElements.length; i++) { if(ComputedStyle = allElements[i].ownerDocument.defaultView.getComputedStyle(allElements[i], "")) { if(url = String(ComputedStyle.getPropertyValue("background-image"))) { if(url != "none") { url = String(url.replace(/^url\(/, "").replace(/\)$/, "")); imgArr.push(url); } } } if(allElements[i].tagName === "IMG") //foreground images { if(url = allElements[i].src) imgArr.push(url); } } } //rtc.LOG("RTC all actions done"); clearTimeout(rtc.blinkTimer); rtc.blinkIcon((clicked === true) ? 0 : 12, doc, null); }, setStylesDisabled: function(disabled, doc){ if(gBrowser && gBrowser.markupDocumentViewer){ gBrowser.markupDocumentViewer.authorStyleDisabled = disabled; doc.stylesDisabled = disabled; } }, blinkIcon: function(num, doc, executed){ if(executed) { var img = document.getElementById('rtc-statusbarimg'); if(num % 2 == 0){ img.setAttribute('src', 'chrome://rtc/skin/rtc.png'); //even number if(num > 11) return; }else img.setAttribute('src', 'chrome://rtc/skin/rtcd.png'); num++; }else if(executed = doc.getElementById('rtc-executed')){ executed.parentNode.removeChild(executed); } rtc.blinkTimer = setTimeout(rtc.blinkIcon, 400, num, doc, executed); }, nullPrompts: function (checked, win, event) { if (checked){ event.preventDefault(); event.stopPropagation(); win.wrappedJSObject.alert = function() {}; win.wrappedJSObject.confirm = function() {}; win.wrappedJSObject.prompt = function() {}; } }, onContentLoaded: function (event) { var head_tag = event.target.getElementsByTagName('head')[0]; if(!head_tag) return; var script_tag = event.target.createElement('script'); script_tag.setAttribute('type', 'text/javascript'); script_tag.setAttribute('id', 'domscr'); var text = "document.docevents = []; var oldDAEL = document.addEventListener; document.addEventListener = function (oldDAEL) {return function (evt, func, bCapture) {oldDAEL.call (this, evt, func, bCapture); document.docevents.push( [evt, func, bCapture] ); } }(oldDAEL); "; text += " document.winevents = []; var oldWAEL = window.addEventListener; window.addEventListener = function (oldWAEL) {return function (evt, func, bCapture) {oldWAEL.call (this, evt, func, bCapture); document.winevents.push( [evt, func, bCapture] ); } }(oldWAEL); "; text += " var domscript = document.getElementById('domscr'); domscript.parentNode.removeChild(domscript); "; script_tag.text = text; head_tag.appendChild(script_tag); }, onShow: function (event) { if(!rtc.getPrefs()[23]) return; setTimeout(rtc.run, 250, event.target); }, onDialog: function (event) { rtc.wrapPrompts(event.target.document, event.target.document.defaultView, event); }, onBeforeUnLoading: function (event) { if(event.originalTarget.stylesDisabled) rtc.setStylesDisabled(false, event.originalTarget); }, //part 4: Disarm prompts (add a checkbox) wrapPrompts: function (doc, win, event) { if(typeof win.wrappedJSObject == "undefined") return; var p = rtc.getPrefs(); if(!p[22] || win.RTCdone || typeof win.wrappedJSObject == "undefined") return; var domain; try{ domain = doc.domain; }catch(e){} var titlemsg = domain ? ("The page at " + doc.domain + " says: ") : "Javascript Application"; var checkmsg = "Stop dialog popups on this page"; var check = {value: false}; win.wrappedJSObject.alert = function (message) { rtc.prompts.alertCheck(win, titlemsg, String(message), checkmsg, check); rtc.nullPrompts(check.value, win, event); } win.wrappedJSObject.confirm = function (message) { var val = rtc.prompts.confirmCheck(win, titlemsg, String(message), checkmsg, check); rtc.nullPrompts(check.value, win, event); return val; } win.wrappedJSObject.prompt = function (message, val) { var input = {value: String(val)}; var val = rtc.prompts.prompt(win, titlemsg, String(message), input, checkmsg, check); rtc.nullPrompts(check.value, win, event); if(val) return input.value; return null; } win.RTCdone = true; }, DisableCSSToggled: function (event) { if(document.getElementById(event.target.id).checked && !navigator.preference("extensions.rtc.noWarningDisableCSS")) { check = {value: false}; if(!rtc.prompts.confirmCheck(null, "RightToClick", "Disabling CSS usually makes pages look strange but might help to save images.\r\n\r\nStill disable CSS?", "Do not show this again", check)) document.getElementById(event.target.id).checked = false; navigator.preference("extensions.rtc.noWarningDisableCSS", check.value); } }, FetchImagesToggled: function () { if(document.getElementById("26").checked) document.getElementById("25").disabled = true; else document.getElementById("25").disabled = false; }, pageInfo: function () { var doc = null; var initialTab = "mediaTab"; var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator); if(wm && wm.getMostRecentWindow("navigator:browser") && wm.getMostRecentWindow("navigator:browser").content) doc = wm.getMostRecentWindow("navigator:browser").content.document; var args = {doc: doc, initialTab: "securityTab"}; window.openDialog('chrome://browser/content/pageinfo/pageInfo.xul', '_blank', 'chrome,toolbar,dialog=no,resizable', args); }, }; document.addEventListener("DOMContentLoaded", rtc.onContentLoaded, true); document.addEventListener("pageshow", rtc.onShow, true); document.addEventListener("stop", rtc.onShow, true); document.addEventListener("beforeunload", rtc.onBeforeUnLoading, true);